﻿using System.Collections.Generic;
using System.Linq;

namespace EFDatabaseFirst
{
    public partial class TerritoriesRepository : ITerritoriesRepository
    {
        public IEnumerable<Territory> GetTerritoriesByRegionId(int id)
        {
            //1
            //IQueryable<Territory> items = 
            //    from item in Territories 
            //    where item.RegionId == id 
            //    select item;
            //2
            IQueryable<Territory> items = Territories.Where(item => item.RegionId == id);

            return new List<Territory>(items);
        }

        public IEnumerable<Territory> GetTerritoriesFilterByDescription(string description)
        {
            IQueryable<Territory> items =
                from item in Territories
                where item.Description.Contains(description)
                select item;

            return new List<Territory>(items);
        }

        public IEnumerable<Region> GetAllRegions()
        {
            var items = new List<Region>(Regions);

            return items;
        }
    }
}